package com.ag.dao;

import java.util.Date;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ag.bean.TbUser;

/**
 * A data access object (DAO) providing persistence and search support for
 * TbUser entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.ag.bean.TbUser
 * @author MyEclipse Persistence Tools
 */

public class TbUserDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(TbUserDAO.class);
	// property constants
	public static final String _UNAME = "UName";
	public static final String _UPASSWORD = "UPassword";
	public static final String _UFAX = "UFax";
	public static final String _UTEL = "UTel";
	public static final String _UPHONE = "UPhone";
	public static final String _UMAIL = "UMail";
	public static final String A = "a";
	public static final String B = "b";
	public static final String C = "c";
	public static final String _UCTI_ID = "UCtiId";
	public static final String _UCTI_NUMBER = "UCtiNumber";
	public static final String _UCTI_QUEUE = "UCtiQueue";
	public static final String _UCTI_PSW = "UCtiPsw";
	public static final String OA_DESCRI = "oaDescri";
	public static final String OA_QQ = "oaQq";
	public static final String OA_MSN = "oaMsn";
	public static final String OA_CERTIFICATE_ID = "oaCertificateId";
	public static final String OA_POSITIONS = "oaPositions";
	public static final String OA_ROLES = "oaRoles";
	public static final String D = "d";
	public static final String E = "e";
	public static final String F = "f";
	public static final String OA_GENDER = "oaGender";
	public static final String OA_SEX = "oaSex";
	public static final String OA_ID_CARD = "oaIdCard";
	public static final String OA_ADDRESS = "oaAddress";
	public static final String OA_ZIP_CODE = "oaZipCode";
	public static final String OA_GROUPS = "oaGroups";
	public static final String OA_CODE = "oaCode";
	public static final String OA_HOME_NUMBER = "oaHomeNumber";
	public static final String OA_OFFICE_NUMBER = "oaOfficeNumber";
	public static final String OA_IS_SHOW = "oaIsShow";

	protected void initDao() {
		// do nothing
	}

	public void save(TbUser transientInstance) {
		log.debug("saving TbUser instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TbUser persistentInstance) {
		log.debug("deleting TbUser instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TbUser findById(java.lang.String id) {
		log.debug("getting TbUser instance with id: " + id);
		try {
			TbUser instance = (TbUser) getHibernateTemplate().get(
					"com.ag.bean.TbUser", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<TbUser> findByExample(TbUser instance) {
		log.debug("finding TbUser instance by example");
		try {
			List<TbUser> results = (List<TbUser>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TbUser instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TbUser as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<TbUser> findByUName(Object UName) {
		return findByProperty(_UNAME, UName);
	}

	public List<TbUser> findByUPassword(Object UPassword) {
		return findByProperty(_UPASSWORD, UPassword);
	}

	public List<TbUser> findByUFax(Object UFax) {
		return findByProperty(_UFAX, UFax);
	}

	public List<TbUser> findByUTel(Object UTel) {
		return findByProperty(_UTEL, UTel);
	}

	public List<TbUser> findByUPhone(Object UPhone) {
		return findByProperty(_UPHONE, UPhone);
	}

	public List<TbUser> findByUMail(Object UMail) {
		return findByProperty(_UMAIL, UMail);
	}

	public List<TbUser> findByA(Object a) {
		return findByProperty(A, a);
	}

	public List<TbUser> findByB(Object b) {
		return findByProperty(B, b);
	}

	public List<TbUser> findByC(Object c) {
		return findByProperty(C, c);
	}

	public List<TbUser> findByUCtiId(Object UCtiId) {
		return findByProperty(_UCTI_ID, UCtiId);
	}

	public List<TbUser> findByUCtiNumber(Object UCtiNumber) {
		return findByProperty(_UCTI_NUMBER, UCtiNumber);
	}

	public List<TbUser> findByUCtiQueue(Object UCtiQueue) {
		return findByProperty(_UCTI_QUEUE, UCtiQueue);
	}

	public List<TbUser> findByUCtiPsw(Object UCtiPsw) {
		return findByProperty(_UCTI_PSW, UCtiPsw);
	}

	public List<TbUser> findByOaDescri(Object oaDescri) {
		return findByProperty(OA_DESCRI, oaDescri);
	}

	public List<TbUser> findByOaQq(Object oaQq) {
		return findByProperty(OA_QQ, oaQq);
	}

	public List<TbUser> findByOaMsn(Object oaMsn) {
		return findByProperty(OA_MSN, oaMsn);
	}

	public List<TbUser> findByOaCertificateId(Object oaCertificateId) {
		return findByProperty(OA_CERTIFICATE_ID, oaCertificateId);
	}

	public List<TbUser> findByOaPositions(Object oaPositions) {
		return findByProperty(OA_POSITIONS, oaPositions);
	}

	public List<TbUser> findByOaRoles(Object oaRoles) {
		return findByProperty(OA_ROLES, oaRoles);
	}

	public List<TbUser> findByD(Object d) {
		return findByProperty(D, d);
	}

	public List<TbUser> findByE(Object e) {
		return findByProperty(E, e);
	}

	public List<TbUser> findByF(Object f) {
		return findByProperty(F, f);
	}

	public List<TbUser> findByOaGender(Object oaGender) {
		return findByProperty(OA_GENDER, oaGender);
	}

	public List<TbUser> findByOaSex(Object oaSex) {
		return findByProperty(OA_SEX, oaSex);
	}

	public List<TbUser> findByOaIdCard(Object oaIdCard) {
		return findByProperty(OA_ID_CARD, oaIdCard);
	}

	public List<TbUser> findByOaAddress(Object oaAddress) {
		return findByProperty(OA_ADDRESS, oaAddress);
	}

	public List<TbUser> findByOaZipCode(Object oaZipCode) {
		return findByProperty(OA_ZIP_CODE, oaZipCode);
	}

	public List<TbUser> findByOaGroups(Object oaGroups) {
		return findByProperty(OA_GROUPS, oaGroups);
	}

	public List<TbUser> findByOaCode(Object oaCode) {
		return findByProperty(OA_CODE, oaCode);
	}

	public List<TbUser> findByOaHomeNumber(Object oaHomeNumber) {
		return findByProperty(OA_HOME_NUMBER, oaHomeNumber);
	}

	public List<TbUser> findByOaOfficeNumber(Object oaOfficeNumber) {
		return findByProperty(OA_OFFICE_NUMBER, oaOfficeNumber);
	}

	public List<TbUser> findByOaIsShow(Object oaIsShow) {
		return findByProperty(OA_IS_SHOW, oaIsShow);
	}

	public List findAll() {
		log.debug("finding all TbUser instances");
		try {
			String queryString = "from TbUser";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TbUser merge(TbUser detachedInstance) {
		log.debug("merging TbUser instance");
		try {
			TbUser result = (TbUser) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TbUser instance) {
		log.debug("attaching dirty TbUser instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TbUser instance) {
		log.debug("attaching clean TbUser instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TbUserDAO getFromApplicationContext(ApplicationContext ctx) {
		return (TbUserDAO) ctx.getBean("TbUserDAO");
	}
}